import jwt from 'jsonwebtoken';
import dotenv from 'dotenv';

// Load environment variables from .env file
dotenv.config();

const generateToken = (id: number) => {
  const secret = process.env.JWT_SECRET;
  if (!secret) {
    throw new Error('JWT Secret not found in environment variables');
  }
  return jwt.sign({ id }, secret, {
    expiresIn: '30d', // Token有效期设置为30天
  });
};

export default generateToken;